/*****************************************************************************
 * Copyright (c) 2010 -, Anders All rights reserved
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 * 
 *  Contact: Anders Uddenberg (anders.uddenberg@gmail.com)
 * 
 *
 ****************************************************************************/
package org.easypr.organizer.client.presenter;

import org.easypr.organizer.client.event.DisplayInformationEvent;

import com.google.gwt.event.shared.HandlerManager;
import com.google.gwt.user.client.ui.HasWidgets;
import com.google.gwt.user.client.ui.Widget;

// TODO: Auto-generated Javadoc
/**
 * The Class InformationPresenter.
 */
public class InformationPresenter implements Presenter {

	/**
	 * Define the interface the view needs to implement.
	 * 
	 * @author Anders
	 */
	public interface Display {
		
		/**
		 * Sets the data.
		 *
		 * @param message the message
		 * @param css the css
		 */
		void setData(String message, String css);

		/**
		 * As widget.
		 * 
		 * @return the widget
		 */
		Widget asWidget();
	}

	/** The event bus. */
	@SuppressWarnings("unused")
	private final HandlerManager eventBus;
	
	/** The display. */
	private final Display display;
	
	/** The message. */
	private String message;
	
	/** The severity. */
	private DisplayInformationEvent.Severity severity;
	
	/**
	 * Instantiates a new menu presenter.
	 *
	 * @param eventBus the event bus
	 * @param view the view
	 * @param message the message
	 * @param severity the severity
	 */
	public InformationPresenter(HandlerManager eventBus, Display view, String message, DisplayInformationEvent.Severity severity) {
		this.eventBus = eventBus;
		this.display = view;
		this.message = message;
		this.severity = severity;
	}

	/* (non-Javadoc)
	 * @see org.easypr.organizer.client.presenter.Presenter#go(com.google.gwt.user.client.ui.HasWidgets)
	 */
	@Override
	public void go(HasWidgets container) {
		container.clear();
		container.add(display.asWidget());
		bind();
		updateContent();
	}
	
	/**
	 * Bind.
	 */
	private void bind() {
	}
	
	
	/**
	 * Main function to update the content of the container.
	 */
	public void updateContent() {
		String css = "";
		switch(this.severity) {
			case INFORMATION:
				css = "info-normal";
				break;
			case SUCCESS:
				css = "info-success";
				break;
			case USER_ERROR:
				css = "info-user-error";
				break;
			case FAILURE:
				css = "info-failure";
				break;
		}
		display.setData(this.message, css);
	}
}